package com.example.aicooking.controller;

import com.example.aicooking.entity.dto.IngredientDTO;
import com.example.aicooking.service.IngredientService;
import com.example.aicooking.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ingredients")
public class IngredientController {
    @Autowired
    private IngredientService ingredientService;

    @GetMapping("/recipe/{workId}")
    public Result<List<IngredientDTO>> getRecipeIngredients(@PathVariable Integer workId) {
        try {
            List<IngredientDTO> ingredients = ingredientService.getIngredientsByWorkId(workId);
            return Result.success(ingredients);
        } catch (Exception e) {
            return Result.error("获取食材列表失败：" + e.getMessage());
        }
    }
}
